<template>
  <div class="header" id="header">
    <div class="header_top">
      <img src="../assets/text.png" class="img" />
      <h1>眼医视觉儿童青少年眼健康管理平台</h1>
      <div class="data"><i class="el-icon-time"></i>{{date}}</div>
    </div>
  </div>
</template>
<script>
import moment from "moment";
export default {
  name: "appHeader",
  data() {
    return {
      date: moment(new Date()).format("YYYY-MM-DD HH:ss:mm")
    };
  },
  methods: {
    timerData() {
      let _this = this; // 声明一个变量指向Vue实例this，保证作用域一致
      this.timer = setInterval(() => {
        _this.date = moment(new Date()).format("YYYY-MM-DD HH:mm:ss"); // 修改数据date
      }, 1000);
    }
  },
  mounted() {
    this.timerData();
  },
  beforeDestroy() {
    if (this.timer) {
      clearInterval(this.timer); // 在Vue实例销毁前，清除我们的定时器
    }
  }
}
</script>
<style scoped>
div,
h1,
h2,
h3,
p,
img {
  padding: 0;
  margin: 0;
}
.header {
  box-sizing: border-box;
  width: 100%;
  height: 100px;
  padding: 15px 10px 0 15px;
}
.header_top {
  text-align: center;
  line-height: 80px;
  color: #ffffff;
  font-size: 20px;
  position: relative;
  background: url("../assets/title.png") no-repeat;
  background-size: 100% 100%;
}
.img {
  width: 180px;
  height: 30px;
  position: absolute;
  left: 200px;
}
.data {
  position: absolute;
  right: 200px;
  top: -20px;
}
.el-icon-time {
  color: #4990c9;
  margin-right: 10px;
}
</style>
